<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    //     输入：nums1 = [1,2], nums2 = [3,4]
    // 输出：2.50000
    // 解释：合并数组 = [1,2,3,4] ，中位数 (2 + 3) / 2 = 2.5
    // 偶数 /2 左边+右边 /2       奇数 /2 向下取整 即可
    let num1 = [1, 2, 3];
    let num2 = [ 4, 5,7];
    console.log(findMedianSortedArrays(num1, num2), "====");
    function findMedianSortedArrays(nums1, nums2) {
      const arr = nums1.concat(nums2).sort((a, b) => a - b);
      const len = arr.length;
      return len % 2 == 0
        ? (arr[len / 2 - 1] + arr[len / 2]) / 2
        : arr[(Math, floor(len / 2))];
    }
  </script>
</html>
